package com.gitee.tje.waving.aop;

import com.gitee.tje.waving.beans.BeanDefinition;
import com.gitee.tje.waving.context.BeanContext;

import java.util.ArrayList;
import java.util.List;

/**
 * @author taojiaen
 * @date 2018-03-18 20:36
 */
public class WavingAop {
    public static void main(String[] args) {
        List<BeanDefinition> beanDefinitions = new ArrayList<>();

        BeanDefinition scannerDefinition = new BeanDefinition();
        scannerDefinition.setBeanName("aopscannder");
        scannerDefinition.setBeanClazz(AopWavingScanner.class.getName());
        beanDefinitions.add(scannerDefinition);


        BeanDefinition applePointDefinition = new BeanDefinition();
        applePointDefinition.setBeanName("applePoint");
        applePointDefinition.setBeanClazz(ApplePointCut.class.getName());
        beanDefinitions.add(applePointDefinition);
        BeanDefinition appleAdvice = new BeanDefinition();
        appleAdvice.setBeanName("appleAdvice");
        appleAdvice.setBeanClazz(AppleMethodHook.class.getName());
        beanDefinitions.add(appleAdvice);
        beanDefinitions.add(applePointDefinition);
        BeanDefinition advisorDefinition = new BeanDefinition();
        advisorDefinition.setBeanName("advisor1");
        advisorDefinition.setBeanClazz(PointCutAdvisor.class.getName());
        advisorDefinition.propertyValues.addRef("advice","appleAdvice");
        advisorDefinition.propertyValues.addRef("pointCut", "applePoint");
        beanDefinitions.add(advisorDefinition);

        BeanDefinition beePointDefinition = new BeanDefinition();
        beePointDefinition.setBeanName("beePoint");
        beePointDefinition.setBeanClazz(BeePointCut.class.getName());
        BeanDefinition beeMethodHoook = new BeanDefinition();
        beeMethodHoook.setBeanName("beeMethodHook");
        beeMethodHoook.setBeanClazz(BeeMethodHook.class.getName());
        beanDefinitions.add(beeMethodHoook);
        beanDefinitions.add(beePointDefinition);
        BeanDefinition advisor2Definition = new BeanDefinition();
        advisor2Definition.setBeanName("advisor2");
        advisor2Definition.setBeanClazz(PointCutAdvisor.class.getName());
        advisor2Definition.propertyValues.addRef("advice","beeMethodHook");
        advisor2Definition.propertyValues.addRef("pointCut", "beePoint");
        beanDefinitions.add(advisor2Definition);



        BeanDefinition beanDefinition = new BeanDefinition();
        beanDefinition.setBeanName("exp");
        beanDefinition.setBeanClazz(AopExample.class.getName());
        beanDefinitions.add(beanDefinition);


        BeanContext beanContext = new BeanContext(beanDefinitions);
        ((AopExample)beanContext.getBean("exp")).testHere();



    }
}
